#include"BlockQueue.hpp"
#include<time.h>
#include<unistd.h>
void* Pro(void* arg)
{
  //pthread_detach(pthread_self());
  BlockQueue<int>* bq = static_cast<BlockQueue<int>*>(arg);
  while(1)
  {
    int data = rand() % 20;
    cout <<pthread_self() <<" 生产的数据为:" << data << endl;
    bq->push(data);
  }
}
void* Com(void* arg)
{
  //pthread_detach(pthread_self());
  BlockQueue<int>* bq = static_cast<BlockQueue<int>*>(arg);
  while(1)
  {
    int data = 0;
    sleep(1);
    bq->pop(&data);
    cout <<pthread_self() <<" 消费的数据为:"<<data << endl;
  }
}
int main()
{
  srand((size_t)time(nullptr));
  BlockQueue<int> bq;
  pthread_t com,pro;
  pthread_create(&com,nullptr,Com,(void*)&bq);
  pthread_create(&pro,nullptr,Pro,(void*)&bq);
  pthread_join(com,nullptr);
  pthread_join(pro,nullptr);
  return 0;
}
